<?php
//Set up the system
require('config.include.php');
//Auth stuff
require('auth.include.php');
//Save data if given
$saved=false;
$rebuilt=false;
//The path to the theme html
$rssFile='../'.RSS_PATH;
if(isset($_POST['rssCode'])) {
	$rssHandle=fopen($rssFile,'w+');
	fwrite($rssHandle,fetch::unescapePostVar($_POST['rssCode']));
	fclose($rssHandle);
	$saved=true;
}
elseif(isset($_GET['rebuild'])) {
	$xml=$_p->rebuildRSS();
	$rssHandle=fopen($rssFile,'w+');
	fwrite($rssHandle,$xml);
	fclose($rssHandle);
	$rebuilt=true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Manage RSS</title>
<link rel="stylesheet" href="admin.css" />
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<?php echo('<a href="../" class="breadcrumb">'.SITE_TITLE.'</a> &raquo; <a href="dashboard.php" class="breadcrumb">Dashboard</a> &raquo; <a href="rss.php" class="breadcrumb">Manage RSS</a>'); ?>
    </div>
    <div id="sidebar">
<?php
	require('nav.include.php');
?>
    </div>
    <div id="content">
			<div class="contentblock">
			<h2>Manage RSS</h2>
			<a href="rss.php?rebuild">Rebuild XML file</a>
			<h2>XML</h2>
			<form action="rss.php" method="post">
				<textarea name="rssCode" class="full" cols="60" rows="30"><?php
				if(file_exists($rssFile))
					$rsscontents=file_get_contents($rssFile);
				else
					$rsscontents='';
				echo(htmlentities($rsscontents,ENT_QUOTES,"UTF-8"));
				?></textarea>
				<br />
				<input type="submit" value="Save Edits"/>
			</form>
			<?php
			if($saved)
				echo('RSS saved.<br />
					If you messed up, just hit rebuild and Pure will rebuild the feed for you.<br />');
			elseif($rebuilt)
				echo('RSS rebuilt.<br />');
			?>
			</div>
    </div>
    <div id="footer">
    </div>
</div>
</body>
</html>